﻿namespace ProjectionTest
    {
    using System;
    using System.IO;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Media;
    using PowerSong.SongDatabase;
    using PowerSong.UserInterface;

    /// <summary>
    /// Interaction logic for TestWindow.xaml
    /// </summary>
    public partial class TestWindow : Window
        {

        private Theatre theatre = new Theatre();

        private string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

        private Song song = null;

        private int verseIndex = 0;

        public TestWindow()
            {
            InitializeComponent();

            // Create a song
            song = new Song("Song Title") { Copyright = "(C) 2013 Nicholas Hill and Nick Music Industries" };

            // Create verses for the song
            var random = new Random();
            for (var verseIndex = 0; verseIndex < 20; verseIndex++)
                {
                var verseText = string.Empty;
                for (var i = 1; i < random.Next(2, 8); i++)
                    {
                    if (verseText != string.Empty) verseText += Environment.NewLine;
                    verseText += random.NextDouble().ToString();
                    }
                song.Verses.Add(verseText);
                }

            // Set the song
            theatre.ChangeText(song.Title, song.Verses.ToArray(), song.Copyright);

            }

        private void CreateControlProjectorButton_Click(object sender, RoutedEventArgs e)
            {
            CreateControlProjectorButton.IsEnabled = false;
            theatre.CreateProjector(TestGrid);
            }

        private void CreateWindowProjectorButton_Click(object sender, RoutedEventArgs e)
            {
            theatre.CreateProjector();
            }

        private void FadeToBlackButton_Click(object sender, RoutedEventArgs e)
            {
            theatre.ChangeMode(ProjectorMode.Black);
            }

        private void FadeToBackgroundButton_Click(object sender, RoutedEventArgs e)
            {
            theatre.ChangeMode(ProjectorMode.Background);
            }

        private void FadeToAllButton_Click(object sender, RoutedEventArgs e)
            {
            theatre.ChangeMode(ProjectorMode.Full);
            }

        private void CrossFadeButton_Click(object sender, RoutedEventArgs e)
            {
            verseIndex = (verseIndex + 1) % song.Verses.Count;
            theatre.ChangeVerse(verseIndex++);
            }

        private void BackgroundDefaultRadioButton_Checked(object sender, RoutedEventArgs e)
            {
            theatre.ResetOverride();
            }

        private void BackgroundColourRadioButton_Checked(object sender, RoutedEventArgs e)
            {
            theatre.OverrideBackground(Colors.DarkGoldenrod);
            }

        private void BackgroundImageRadioButton_Checked(object sender, RoutedEventArgs e)
            {
            var fileName = Path.Combine(location, "Sample.jpg");
            theatre.OverrideBackground(fileName);
            }

        private void BackgroundVideoRadioButton_Checked(object sender, RoutedEventArgs e)
            {
            var fileName = Path.Combine(location, "Sample.mp4");
            theatre.OverrideBackground(fileName, TimeSpan.FromSeconds(0), 0, 1, true);
            }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
            theatre.RemoveAllProjectors();
            }

        }

    }
